Responsive Email Design 您所在的位置:网站首页 how to design a responsive web page in html Responsive Email Design

Responsive Email Design

2023-03-30 20:00| 来源: 网络整理| 查看: 265

While phone screen sizes have been steadily increasing over the years along with screen resolution, it can be tempting to include more and more images in your emails. But a word of caution: While images can bring an extra wow factor to your emails, images should always be thoughtfully added with accessibility and mobile load times top of mind.

In this chapter, we’ll look at some techniques that take advantage of supported CSS properties like background-image. These techniques will not only allow you to display mobile-optimized images throughout your designs, but ensure they look crisp at any width.

Using background images for better headers

Support and the use of background images have been on the rise in the last couple of years thanks in part to increased CSS support utilizing all the benefits that media queries can bring.

One benefit of the increased support is the ability to put live text on images. Another benefit is being able to substitute images when an email campaign is viewed on a mobile device by hiding the original and letting the beautiful, mobile-friendly image shine through.

Background images and live text

In the past, if you wanted to include text on an image, it was created as a single graphic. And if that image didn’t load, you were at the mercy of your alt text. Now, with greater support for background images, you can have live text and buttons along with the beautiful images.

Let’s see how this is done.

Background images in Outlook: setting up a DOCTYPE

At the top of your HTML email you’ll need to declare the DOCTYPE. Doing so informs the browser that this will be an HTML document.

Next, we’ll set up our HTML tag, declaring the language as en, which will tell screen readers that this email is written in English. If you’re writing emails in other languages, W3Schools.com has created a list of ISO language codes.

The second half of this code will be a VML or Vector Markup Language declaration, so Microsoft Outlook will allow us to create background images.

Next, we’ll insert our 120 DPI scaling to target Outlook 2007-2013 and ensure our email scales correctly. This code is placed in the tag and outside of the tag.

The top of your email should look something like this:

code snippet showing background image

Email Sample html { width: 100%; } @media only screen and (max-width: 600px) { /* Table styles go here */ } @media only screen and (max-width: 479px) { /* mobile styles go here */ }

So let’s put it all together.

code snippet with correct spacing and shaping for bulletproof backgrounds in outlook

Are you ready for;your next;adventure?

It’s generally recommended that images be resized to fit within a viewport of mobile devices. But there are special occasions when your design doesn’t allow this, resulting in a small image with illegible text.

Using unique images for mobile devices

If using a background image with live text (as seen in the example above) is not an option, you can create a unique image specifically for mobile devices. This can be accomplished by surrounding the image in a table cell or , then creating a media query that hides the original and shows another header image as a background image instead:

CSS @media only screen and (max-device-width: 479px) { .headerimg { background-image: url(https://yourdomain.com/images/header-325.png); width: 100% !important; height: 115px !important; } .imgheader { display: none; } } HTML

Here’s how things look before and after the header images have been swapped out:

rendered example of image being replaced based on the mobile device

An advantage to using this technique is that you can shorten the length of emails by providing significantly shorter images. Or you can restyle your images and text to enhance the mobile experience. When it comes to mobile email, the shorter, the better.

Resizing images for fluid layouts

The issue with the background image swap method above is that it’s really only effective with static-width email designs.

These days, mobile devices can come in all sorts of shapes and sizes, therefore making fluid email layouts a popular option. While the obvious solution seems to be to set background-size: 100% in the earlier media query, as Elliot Jay Stocks points out, the better option is to use background-size: cover:

@media only screen and (max-width: 600px) { .imgheader { width: 100% !important; } } @media only screen and (max-width: 479px) { .headerimg { background-image: url(https://engage.sailthru.com/rs/500-BIA-880/images/hero_img_mobile.jpg);   width: 100% !important; height: 300px !important; background-position: center !important; background-repeat: no-repeat !important; } .imgheader { display: none; } } Serving high-res images for Retina displays

Our final tip is in regards to getting images to display as sharply as possible on Apple’s Retina displays. This is one that we’ve covered before, but given that these displays aren’t going away anytime soon, it’s worth a recap.

The trick is to create key images at twice the size you actually plan on displaying them, thus making the image look super crisp on iPhone 11 and iPad displays. For example, using our earlier background image hack, we’d create a header image that was really 600px x 300px (e.g. https://[email protected]), but then shrink it down for mobile screens.

Here’s how the media query would look:

@media only screen and (max-width: 600px) { .imgheader { width: 100% !important; } } @media only screen and (max-width: 479px) { .headerimg { background-image: url(https://[email protected]); width: 100% !important; height: 150px !important; background-position: center !important; background-repeat: no-repeat !important; } .imgheader { display: none; } }

If you specifically want to target Retina displays with a special stylesheet, you can use this CSS declaration instead:

@media all and (min-device-pixel-ratio : 1.5) { ... }

While doubling the size of your images will produce sharp images for larger displays (i.e. iPads and tablets), they can also weigh your emails down, creating slow load times and an overall poor experience for your subscribers.

You can help prevent slow load times with the Save for web options when you export your images from Photoshop or Sketch. You can also utilize an image compressor like TinyPng. For more information on using retina images, we recommend reading this post by Litmus.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有